/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clueless;

import javax.swing.JLabel;

/**
 *
 * @author dcain
 */
public class StartEndDialog extends javax.swing.JFrame {

    /**
     * Creates new form StartEndDialog
     */
    public StartEndDialog() {
      initComponents();
    }
    
    public StartEndDialog(String charsClaimed) {        
        
        int charToProcess = 0;
        String [] claimed = null;
        if (charsClaimed.length() > 0){
            claimed = charsClaimed.split(" ");
            charToProcess = claimed.length -1;
        }
        
        boolean firstGoodFound = true;
        while(charToProcess > 0){
            switch(claimed[charToProcess]){
                case "Scarlet":
                    scarletRadio.setEnabled(false);
                    plumRadio.setSelected(true);
                    firstGoodFound = false;
                    charToProcess --;
                    break;
                case "Plum":
                    plumRadio.setEnabled(false);
                    if(!firstGoodFound){
                        whiteRadio.setSelected(true);
                    }
                    charToProcess --;
                    break;
                case "White":
                    whiteRadio.setEnabled(false);
                    if(!firstGoodFound){
                        greenRadio.setSelected(true);
                    }
                    charToProcess --;
                    break;
                case "Green":
                    greenRadio.setEnabled(false);
                    if(!firstGoodFound){
                        peacockRadio.setSelected(true);
                    }
                    charToProcess --;
                    break;
                case "Peacock":
                    peacockRadio.setEnabled(false);
                    if(!firstGoodFound){
                        mustardRadio.setSelected(true);
                    }
                    charToProcess --;
                    break;
                case "Mustard":
                    mustardRadio.setEnabled(false);                    
                    charToProcess --;
                    break;
            }
        }
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        startButton = new javax.swing.JButton();
        title = new javax.swing.JLabel();
        scarletRadio = new javax.swing.JRadioButton();
        plumRadio = new javax.swing.JRadioButton();
        whiteRadio = new javax.swing.JRadioButton();
        greenRadio = new javax.swing.JRadioButton();
        peacockRadio = new javax.swing.JRadioButton();
        mustardRadio = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        startButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        startButton.setText("Start");
        startButton.setEnabled(false);
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        title.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        title.setLabelFor(this);
        title.setText("Welcome to Clueless!");
        title.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        buttonGroup1.add(scarletRadio);
        scarletRadio.setSelected(true);
        scarletRadio.setText("Scarlet");

        buttonGroup1.add(plumRadio);
        plumRadio.setText("Prof Plum");

        buttonGroup1.add(whiteRadio);
        whiteRadio.setText("White");

        buttonGroup1.add(greenRadio);
        greenRadio.setText("Green");

        buttonGroup1.add(peacockRadio);
        peacockRadio.setText("Peacock");

        buttonGroup1.add(mustardRadio);
        mustardRadio.setText("Col Mustard");

        jLabel1.setText("Waiting on other Players");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scarletRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(plumRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(whiteRadio)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(greenRadio)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(peacockRadio)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mustardRadio))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(127, 127, 127)
                        .addComponent(title))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(jLabel1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(scarletRadio)
                    .addComponent(plumRadio)
                    .addComponent(whiteRadio)
                    .addComponent(greenRadio)
                    .addComponent(peacockRadio)
                    .addComponent(mustardRadio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(startButton)
                .addGap(34, 34, 34))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public void setTitle(String text){
        title.setText(text);
        jLabel1.setText("");
        startButton.setEnabled(true);
    }
    
    public void setChars(String charsTaken){
        if(charsTaken.length()>0){
            String [] chars = charsTaken.split(" ");
            boolean firstGoodFound = true;
            for(int i = 0; i < chars.length; i++){
                switch(chars[i]){
                case "Scarlet":
                    scarletRadio.setEnabled(false);
                    plumRadio.setSelected(true);
                    firstGoodFound = false;                    
                    break;
                case "Plum":
                    plumRadio.setEnabled(false);
                    if(!firstGoodFound){
                        whiteRadio.setSelected(true);
                    }
                    
                    break;
                case "White":
                    whiteRadio.setEnabled(false);
                    if(!firstGoodFound){
                        greenRadio.setSelected(true);
                    }
                    
                    break;
                case "Green":
                    greenRadio.setEnabled(false);
                    if(!firstGoodFound){
                        peacockRadio.setSelected(true);
                    }
                    
                    break;
                case "Peacock":
                    peacockRadio.setEnabled(false);
                    if(!firstGoodFound){
                        mustardRadio.setSelected(true);
                    }
                    
                    break;
                case "Mustard":
                    mustardRadio.setEnabled(false);                   
                    
                    break;
                }
            }
        }
    }
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        String sel = "";
            if(scarletRadio.isSelected()){
                sel = "Scarlet";                
            } else if (plumRadio.isSelected()){
                sel = "Plum";               
            } else if (whiteRadio.isSelected()){
                sel = "White";                
            } else if (greenRadio.isSelected()){
                sel = "Green";               
            } else if (peacockRadio.isSelected()){
                sel = "peacock";               
            } else if (mustardRadio.isSelected()){
                sel = "Mustard";               
            }
        
        Clueless.out.println(sel);
        dispose();
    }//GEN-LAST:event_startButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton greenRadio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton mustardRadio;
    private javax.swing.JRadioButton peacockRadio;
    private javax.swing.JRadioButton plumRadio;
    private javax.swing.JRadioButton scarletRadio;
    private javax.swing.JButton startButton;
    private javax.swing.JLabel title;
    private javax.swing.JRadioButton whiteRadio;
    // End of variables declaration//GEN-END:variables
}
